package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.model.product.SpuInfo;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author LEO
 * @Date 2021年12月10日 21:54
 */
@Api(tags = "品牌信息接口")
@RestController
@RequestMapping("admin/product/baseTrademark")
public class BaseTrademarkController {


    //分页查询所有品牌
    @Autowired
    private BaseTrademarkService baseTrademarkService;
    // http://api.gmall.com/admin/product/baseTrademark/{page}/{limit}
    @GetMapping("{page}/{limit}")
    public Result getBaseTrademarkList(@PathVariable("page") Long page,
                                       @PathVariable("limit") Long limit){
        //声明一个page对象
        Page<BaseTrademark> baseTrademarkPage = new Page<>(page, limit);
        IPage iPage =baseTrademarkService.getBaseTrademarkList(baseTrademarkPage);
        // IPage 下有List<T> getRecords
        return Result.ok(iPage);
    }

    //保存品牌
    //http://api.gmall.com/admin/product/baseTrademark
    @PostMapping("save")
    public Result save(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }


    // 修改品牌
    @PutMapping("update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    //删除品牌
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable("id") Long id){
        baseTrademarkService.removeById(id);
        return  Result.ok();
    }


    // 根据id获取品牌
    @GetMapping("get/{id}")
    public Result getBaseTrademark(@PathVariable("id") Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);

    }

    //加载销售属性
    //	http://api.gmall.com/admin/product/baseSaleAttrList
    @GetMapping("getTrademarkList")
    public Result getTrademarkList(){
        return Result.ok(baseTrademarkService.list(null));
    }




}
